package ae.pcfc.etks.online.itworx.ehs.web.web.util;

import org.apache.commons.lang.ClassUtils;
import org.springframework.validation.BindingResult;

import ae.pcfc.etks.online.itworx.ehs.web.constants.GlobalConstants;
import ae.pcfc.etks.online.itworx.ehs.web.exception.SystemException;

public class ViewUtils {

	/*
	 * so steps will be as follows 1- go define ViewPath in ViewPath (if not
	 * already defined) like company/register/nonclient 2- if the pageType is
	 * not defined go define it in PageType like add,edit,form,etc 3- use
	 * getForward or getRedirect 4- define a constant value for view if it does
	 * not follow a pattern (use with caution)
	 */

	public static final String DEFAULT_VIEW = null;

	private ViewUtils() {
	}

	/*
	 * public static String decodeParam(String param) {
	 * 
	 * }
	 */

	public static String addExceptionError(SystemException exception,
			BindingResult errors) {
		
		String message = null;

		String messageKey = GlobalConstants.EXCEPTION_MESSAGES_PREFIX;
		String exceptionKey = ClassUtils.getShortClassName(exception, null)
				.toLowerCase();
		if (exceptionKey == null) {
			return message;
		}

		messageKey += exceptionKey;
		if (exception != null && exception.getErrorMessageArgList().size()!=0) {

			errors.reject(messageKey,
					exception.getErrorMessageArgList().toArray(new String[0]), null);
		} 

		return message;
	}

}
